<?php
class Business_TotalView{
	/**
	 * 
	 * @return Array | Zend_Exception
	 */
	
	
	/**
	 * 
	 * @param $params['key'] = CustomerID,CustomerName | $params['value'] = 1, Name
	 * @return Array
	 */
	public static function get($realId){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_getTotalView(:s_RealId)');
			$stmt->bindValue('s_RealId',$realId);
			$stmt->execute();
			$result = $stmt->fetchAll();
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return array();
		}
	}
	

	public static function create($params){
		try {
			
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_insertCustomer(:s_RealId,
:s_TotalView
,:s_LastVisit)');
			$stmt->bindValue('s_RealId',$params['RealId']);
			$stmt->bindValue('s_TotalView',1);
			$stmt->bindValue('s_LastVisit',time());
			
			$stmt->execute();
			$result = $stmt->rowCount();
			
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return 0;
		}
	}
	/**
	 * 
	 * @param unknown_type $params
	 * @return number
	 */
	public static function update($params){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_updateTotalView(:s_RealId,:s_LastVisit)');
			$stmt->bindValue('s_RealId',$params['CustomerId']);
			$stmt->bindValue('s_LastVisit',time());
			$stmt->execute();			
			
			$result = $stmt->rowCount();
			
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return 0;
		}
	}
	
	public static function delete($RealIds){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare("CALL sp_deletetotalview(:s_RealId)");
			$stmt->bindValue('s_RealId',$RealIds);
			$stmt->execute();
			return $stmt->rowCount();
		} catch (Zend_Exception $e) {
			return $e->getMessage();
		}
	}
}